﻿@using A2.ERP.Models
@{
    List<t_Supplier> suppliersList = ViewBag.supplier;
}

<section id="SysSupplierManager">
    @*<div class="card">
            <div class="card-header">筛选</div>
            <div class="card-body">
                @using (Html.BeginForm("SysProductsTypeManager", "Setting", FormMethod.Post, new
                {
                    @class = "form"
                }))
                {

                }
            </div>
        </div>*@
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>供应商</th>
                <th>地区</th>
                <th>联系人</th>
                <th>电子邮箱</th>
                <th>电话</th>
                <th>企业网站</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            @foreach (var suppliers in suppliersList)
            {
                <tr>
                    <td>@suppliers.SupplierName</td>
                    <td>@suppliers.Area</td>
                    <td>
                        @suppliers.Linkman
                    </td>
                    <td>
                        @suppliers.Email
                    </td>
                    <td>
                        @suppliers.Tel
                    </td>
                    <td><a href="@suppliers.WebUrl">跳转</a></td>
                    <td>
                        <button class="btn btn-sm btn-success" data-target="#addSupplierModal" data-toggle="modal">
                            <i class="icon SkyUI icon-plus"></i>
                            添加
                        </button>
                        <a data-route="setting/EditSupplier?id=@suppliers.SupplierID">
                            <button class="btn btn-sm btn-primary">
                                <i class="icon SkyUI icon-search"></i>
                                编辑
                            </button>
                        </a>
                        <button class="btn btn-sm btn-danger btn-DelSupplier" data-id="@suppliers.SupplierID" data-target="#DelSupplierModal" data-toggle="modal">
                            <i class="icon SkyUI icon-close"></i>
                            删除
                        </button>
                    </td>
                </tr>
            }
        </tbody>
    </table>

    <!-- add -->
    <div class="modal fade" id="addSupplierModal" tabindex="-1" role="dialog" aria-labelledby="addSupplierModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">添加数据</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    @using (Html.BeginForm("SysSupplierManager", "Setting", FormMethod.Post, new
                    {
                        @class = "addSupplierFrm"
                    }))
                    {
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-prepend">
                                    <label class="input-group-text">供应商</label>
                                </div>
                                <input type="text" name="SupplierName" value="" class="form-control" />
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-prepend">
                                    <label class="input-group-text">所属地区</label>
                                </div>
                                <input type="text" name="Area" value="" class="form-control" />
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-prepend">
                                    <label class="input-group-text">联系人</label>
                                </div>
                                <input type="text" name="Linkman" value="" class="form-control" />
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-prepend">
                                    <label class="input-group-text">邮编</label>
                                </div>
                                <input type="text" name="PostCode" value="" class="form-control" />
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-prepend">
                                    <label class="input-group-text">通讯地址</label>
                                </div>
                                <input type="text" name="Address" value="" class="form-control" />
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-prepend">
                                    <label class="input-group-text">电话</label>
                                </div>
                                <input type="text" name="Tel" value="" class="form-control" />
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-prepend">
                                    <label class="input-group-text">企业网站</label>
                                </div>
                                <input type="text" name="WebUrl" value="" class="form-control" />
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-prepend">
                                    <label class="input-group-text">邮箱</label>
                                </div>
                                <input type="text" name="Email" value="" class="form-control" />
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-prepend">
                                    <label class="input-group-text">纳税号</label>
                                </div>
                                <input type="text" name="BankAccount" value="" class="form-control" />
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <div class="input-group-prepend">
                                    <label class="input-group-text">备注</label>
                                </div>
                                <input type="text" name="Description" value="" class="form-control" />
                            </div>
                        </div>
                        <div class="form-group">
                            <div class="input-group">
                                <button class="btn btn-success" type="submit">添加</button>
                                <button class="btn btn-primary" data-dismiss="modal">取消</button>
                            </div>
                        </div>
                    }
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="DelSupplierModal" tabindex="-1" role="dialog" aria-labelledby="sysGroupModalLabel" aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">确定要删除该权限组吗？</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    确定要删除该权限组吗?
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">取消</button>
                    <button type="button" class="btn btn-primary btn-sureDelSupplier">确定</button>
                </div>
            </div>
        </div>
    </div>
</section>

<script>
    ;
    !function () {
        var $addSupplierFrm = $('#SysSupplierManager .addSupplierFrm');
        var $btnDelSupplier = $('#SysSupplierManager .btn-DelSupplier');
        var $btnSureDelSupplier = $('#SysSupplierManager .btn-sureDelSupplier');

        var currentID = null;

        $btnDelSupplier.on('click', function () {
            currentID = $(this).attr('data-id');
        });

        $btnSureDelSupplier.on('click', function () {
            $.ajax({
                url: '/setting/SysSupplierManager',
                dataType: 'json',
                type: 'DELETE',
                data: { id: currentID },
                success: function (data) {
                    if (data) {
                        $('.modal').modal('hide');
                        $tab.reloadTab('#SysSupplierManager');
                    }
                }
            });
        });

        $addSupplierFrm.on('submit', function (e) {
            e.preventDefault();

            $addSupplierFrm.ajaxSubmit({
                method: 'POST',
                dataType: 'json',
                success: function (data) {
                    $('.modal').modal('hide');
                    $tab.reloadTab('#SysSupplierManager');
                }
            })
        })
    }();
</script>